/*
 * @Description: 原型链继承
 * @Author: rendc
 * @Date: 2021-09-03 14:20:36
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-03 14:40:51
 */
function Animal (name, age) {
  this.name = name;
  this.age = age;
}
Animal.prototype.sayName = function () {
  console.log(this.name);
}
Animal.prototype = {
  constructor: Animal,
  sayHello: function () {
    console.log(this.name + "say hello!");
  }
}
function Dog (name, age, color) {
  this.name = name;
  this.age = age;
  this.color = color;
}
// console.log(Dog.prototype);

// 原型链继承
Dog.prototype = new Animal();
// console.log(Dog.prototype);

Dog.prototype.constructor = Dog;

Dog.prototype.sayColor = function () {
  console.log(this.color);
}
var dog = new Dog("金毛", 1, "yellow");
console.log(dog);
dog.sayHello();               // Animal.prototype
dog.sayColor();               // Dog.prototype
console.log(dog.toString());  // Object.prototype
console.log(typeof dog);
console.log(dog instanceof Dog); //true
console.log(dog instanceof Animal); //true
console.log(dog instanceof Object); //true
console.log(dog instanceof Date); //false
// 是否是该原型派生出来的对象
console.log(Object.prototype.isPrototypeOf(dog));// true
console.log(Animal.prototype.isPrototypeOf(dog));// true
console.log(Date.prototype.isPrototypeOf(dog));// false